function [ k ] = gibbs_sample(m,t,n_mk,n_kt,alpha,beta)
    P = zeros(1,3);
    %P(z_i = k|zbar_i',wbar) = n_ki^t + beta_t * n_mi^k + alpha_k
    %n_ki^t = how many times do all other words see topic k?
    
    for k=1:size(n_kt,1)
        top = (n_kt(k,t)+beta(t))*(n_mk(m,k)+alpha(k));
        da = 0;
        db = 0;
        db = sum(n_kt(k,:))+sum(beta);
        da = sum(n_mk(m,:))+sum(alpha);
        for v=1:size(n_kt,2)
            db = db + n_kt(k,v)+beta(v);
        end
        for j=1:size(n_mk,2)
            da = da + n_mk(m,j)+alpha(j);
        end
        P(k) = top / (db*da);
    end
    
    P = P/sum(P);
    k = randsample(size(n_kt,1),1,true,P);
end

